//
//  DutyScreeningView.m
//  Nurse
//
//  Created by zhangp on 13-12-17.
//  Copyright (c) 2013年 RainSets. All rights reserved.
//

#import "BedScreeningView.h"
#import "ScreeningTitleCell.h"
#import "ScreeningViewCell.h"
#import "OperatorService.h"
#import "BedViewController.h"

@interface BedScreeningView ()

@end

@implementation BedScreeningView


-(void)setViewStyle{
    self.backgroundColor=[UIColor clearColor];
    self.bgimg.backgroundColor=[UIColor whiteColor];
    self.table_View.showsVerticalScrollIndicator=NO;//竖线
    self.table_View.frame=CGRectMake(0, 20, self.table_View.frame.size.width, self.frame.size.height);
}





-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    CGPoint touch=[[touches anyObject] locationInView:self];
    if (touch.x>0 && touch.y>0) {
        
        [self removeFromSuperviewWithAnimation];
        
    }
    
}

-(void)removeFromSuperviewWithAnimation{
    [UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self setFrame:CGRectMake(-self.table_View.frame.size.width, 0.f, self.frame.size.width, self.frame.size.height)];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        return 63.5f;
    }else{
        return 45.0f;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    OperatorService* service  = [OperatorService sharedInstance];
    
    return [[service currentOperatorWards]count]+1;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"ScreeningViewCell";
    OperatorService* service  = [OperatorService sharedInstance];

    
    ScreeningViewCell *cell = (ScreeningViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
        
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ScreeningViewCell" owner:self options:nil];
        cell = (ScreeningViewCell *)[nib objectAtIndex:0];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    cell.img.hidden=YES;
    
    
    if (indexPath.row==0) {
        cell.contentLab.frame=CGRectMake(20.f, 10.f, tableView.frame.size.width - 20.f, cell.frame.size.height - 10.f);
        [cell.contentLab setTextColor:[UIColor lightGrayColor]];
        cell.contentLab.text=@"选择病区";
        return cell;
    }else{
        cell.contentLab.frame=CGRectMake(20.f, 0.f, tableView.frame.size.width - 20.f, cell.frame.size.height);
//       [cell.hookImg setFrame:CGRectMake(cell.hookImg.frame.origin.x, cell.frame.size.height / 2.f - cell.hookImg.frame.size.height, cell.hookImg.frame.size.width, cell.hookImg.frame.size.height)];
        
        
        [cell.hookImg setFrame:CGRectMake(206,13,26,21)];
        cell.hookImg.image=[UIImage imageNamed:@"current-icon.png"];//sure_btn.png
        
        NSDictionary* ward = [[service currentOperatorWards]objectAtIndex:indexPath.row-1];
        
        cell.contentLab.text= [ward valueForKey:@"科室名称"];//@"南八楼";//[NSString stringWithFormat:@"南八楼",indexPath.row];
        
        NSString* currentCode = [[OperatorService sharedInstance]currentOperatorWardCode];
        NSArray* wards = [[OperatorService sharedInstance]currentOperatorWards];
        for (int i =0;i<[wards count];++i) {
            NSDictionary* ward=[wards objectAtIndex:i];
            NSString* code = [ward valueForKey:@"科室代码"];
            if ([code isEqualToString:currentCode]) {
                self.typeChoose = i;
                break;
            }
        }
        
        if (indexPath.row-1==self.typeChoose) {
            cell.contentLab.textColor=[UIColor whiteColor];
            cell.hookImg.hidden=NO;
            cell.bgimg.backgroundColor=CustomCellColor;
        }else{
            cell.contentLab.textColor=[UIColor blackColor];
            cell.hookImg.hidden=YES;
            cell.bgimg.backgroundColor=[UIColor whiteColor];
        }
        return cell;
    }
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row>0) {
        self.typeChoose=indexPath.row-1;
        NSDictionary* ward = [[[OperatorService sharedInstance]currentOperatorWards]objectAtIndex:self.typeChoose];
        
        [tableView reloadData];
        NSString* code = [ward valueForKey:@"科室代码"];
        
        [self.parent setupDataWithWardCode:code];
        [self removeFromSuperviewWithAnimation];
        
    }
    
    
}






@end
